import React, { useReducer } from 'react';

//reducer 的 example
function reducer(state,action){
    switch(action){
        case "add":
            return state + 1;
        case "sub":
            return state - 1;
        default:
            return state;
    }
}

function Reducer(){
    const [count , dispatch] = useReducer(reducer,0);
    return (
        <div>
            <h3>Reducer的使用</h3>
            <h2>现在的分数是{count}</h2>
            <button onClick={()=>dispatch('add')}>Increment</button>
            <button onClick={()=>dispatch('sub')}>Decrement</button>
        </div>
    )
}


export default Reducer;